unit QImport3WideStringCanvas;

{$I QImport3VerCtrl.Inc}

interface

{$IFDEF QI_UNICODE}

uses
  Graphics, Controls, Windows;

type
   TEmsWideStringCanvas = class(TControlCanvas)
   public
     function TextExtentW(const Text: WideString): TSize;
     function TextHeightW(const Text: WideString): Integer;
     function TextHeight(const Text: WideString): Integer; overload;
     procedure TextOutW(X, Y: Integer; const Text: WideString);
     procedure TextOut(X, Y: Integer; const Text: WideString);
        {$IFDEF VCL14} reintroduce; {$ELSE} overload; {$ENDIF}
     procedure TextRectW(Rect: TRect; X, Y: Integer; const Text: WideString);
     procedure TextRect(Rect: TRect; X, Y: Integer; const Text: WideString); overload;
     function TextWidthW(const Text: WideString): Integer;
     function TextWidth(const Text: WideString): Integer; overload;
   end;

{$ENDIF}

implementation

{$IFDEF QI_UNICODE}

{ TEmsWideStringCanvas }

function TEmsWideStringCanvas.TextExtentW(const Text: WideString): TSize;
begin
  RequiredState([csHandleValid, csFontValid]);
  Result.cX := 0;
  Result.cY := 0;
  Windows.GetTextExtentPoint32W(Handle, PWideChar(Text), Length(Text), Result);
end;

function TEmsWideStringCanvas.TextHeightW(const Text: WideString): Integer;
begin
  Result := TextExtentW(Text).cY;
end;

function TEmsWideStringCanvas.TextHeight(const Text: WideString): Integer;
begin
  Result := TextExtentW(Text).cY;
end;

procedure TEmsWideStringCanvas.TextOutW(X, Y: Integer;
  const Text: WideString);
begin
  Changing;
  RequiredState([csHandleValid, csFontValid, csBrushValid]);
  if CanvasOrientation = coRightToLeft then
    Inc(X, TextWidthW(Text) + 1);
  Windows.ExtTextOutW(Handle, X, Y, TextFlags, nil, PWideChar(Text),
    Length(Text), nil);
  MoveTo(X + TextWidthW(Text), Y);
  Changed;
end;

procedure TEmsWideStringCanvas.TextOut(X, Y: Integer;
  const Text: WideString);
begin
  Changing;
  RequiredState([csHandleValid, csFontValid, csBrushValid]);
  if CanvasOrientation = coRightToLeft then
    Inc(X, TextWidth(Text) + 1);
  Windows.ExtTextOutW(Handle, X, Y, TextFlags, nil, PWideChar(Text),
    Length(Text), nil);
  MoveTo(X + TextWidth(Text), Y);
  Changed;
end;

procedure TEmsWideStringCanvas.TextRectW(Rect: TRect; X, Y: Integer;
  const Text: WideString);
var
  Options: Longint;
begin
  Changing;
  RequiredState([csHandleValid, csFontValid, csBrushValid]);
  Options := ETO_CLIPPED or TextFlags;
  if Brush.Style <> bsClear then
    Options := Options or ETO_OPAQUE;
  if ((TextFlags and ETO_RTLREADING) <> 0) and
      (CanvasOrientation = coRightToLeft) then
    Inc(X, TextWidthW(Text) + 1);
  Windows.ExtTextOutW(Handle, X, Y, Options, @Rect, PWideChar(Text),
    Length(Text), nil);
  Changed;
end;

procedure TEmsWideStringCanvas.TextRect(Rect: TRect; X, Y: Integer;
  const Text: WideString);
var
  Options: Longint;
begin
  Changing;
  RequiredState([csHandleValid, csFontValid, csBrushValid]);
  Options := ETO_CLIPPED or TextFlags;
  if Brush.Style <> bsClear then
    Options := Options or ETO_OPAQUE;
  if ((TextFlags and ETO_RTLREADING) <> 0) and
      (CanvasOrientation = coRightToLeft) then
    Inc(X, TextWidth(Text) + 1);
  Windows.ExtTextOutW(Handle, X, Y, Options, @Rect, PWideChar(Text),
    Length(Text), nil);
  Changed;
end;

function TEmsWideStringCanvas.TextWidthW(const Text: WideString): Integer;
begin
  Result := TextExtentW(Text).cX;
end;

function TEmsWideStringCanvas.TextWidth(const Text: WideString): Integer;
begin
  Result := TextExtentW(Text).cX;
end;

{$ENDIF}

end.
